<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui, viewport-fit=cover">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta name="format-detection" content="telephone=no">
    <title>支付</title>
    <style>
        body {
            background-color: #fff;
        }
        .pay {
            display: flex;
            margin: 0 auto;
            align-items: center;
            justify-content: center;
            text-align: center;
            margin-top: 50%;
            width: 20rem;
            height: 5rem;
            color: #fff;
            background-color: #4CAF50;
            font-size: 1.6rem;
            cursor: pointer;
            outline: none;
            border: 0px;
            border-radius: 6rem;
            -webkit-appearance: none;
            -webkit-tap-highlight-color: transparent;

        }

        html {
            font-family: '微软雅黑';
            max-width: 750px;
            margin: 0 auto
        }

        * {
            margin: 0;
            padding: 0;
        }

        a {
            text-decoration: none;
            outline: none;
            -webkit-tap-highlight-color: transparent
        }

        ul li {
            list-style: none
        }

        @media screen and (min-width:320px) and (max-width:359px) {
            html {
                font-size: 9px;
            }

        }

        @media screen and (min-width:360px) and (max-width:374px) {
            html {
                font-size: 10px;
            }

        }

        @media screen and (min-width:375px) and (max-width:413px) {
            html {
                font-size: 11px;
            }

        }

        @media screen and (min-width:414px) and (max-width:450px) {
            html {
                font-size: 12px;
            }

        }

        @media screen and (min-width:750px) {
            html {
                font-size: 14px;
            }

        }
    </style>
</head>

<body>
<div class="weui-btn-area">

    <a class="pay default-btn" href="javascript:void(0)" onclick="orderSubmit()">点 我 支 付</a>
</div>
<form action="" method="POST" id="myform" style="display: none;">
    <button type="button" onclick='doSubmitForm()'>提交</button>
</form>

<!-- jQuery -->
<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
<script>
    var DemoUrl;
    var countdown = 5;//倒计时
    var code = <%=request.getParameter("erroeCode")%>
    <%--var returnurl=${returnObject};--%>
    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            obj.attr('onclick', "sendemail()");
            obj.css('color', '#fff');
            obj.html("点我支付");
            countdown = 5;
            if (returnurl==""){
                alert("参数错误，调用支付失败");
            }
            // $("#myform").click(function () {
            //     orderSubmit()
            // })//此处url为接口返回的支付地址
            $("#myform").submit();
            return;
        } else {
            obj.removeAttr('onclick');
            obj.css('color', '#fff');
            obj.html("正在支付（" + countdown + "）");
            countdown--;
        }
        setTimeout(function () {
            settime(obj)
        }, 1000)
    };

    //支付事件
    function orderSubmit(){
        // settime(obj);
        $.ajax({
            // url:'https://sbd.sbdznkj.com/callTest/getH5pay?amount=12.5&applydate=2020-05-03 00:00:00&attach=test&bankcode=2002&callbackurl=www.baidu.com&md5sign=test&memberid=1&notifyurl=www.baidu.com&orderid=123456&productdesc=test&productname=test&productnum=test&producturl=test&sign=435205FD819C799E4D60553A503EE206',
            // url:'http://localhost:8081/WxWebH5Pay/getH5pay',
            url:'http://www.dayuanbao.ltd/SbdVoip/WxWebH5Pay/getH5pay2',
            type: 'POST',
            data:{
                memberid:"<%=request.getParameter("memberid")%>",
                orderid:"<%=request.getParameter("orderid")%>",
                amount:"<%=request.getParameter("amount")%>",
                applydate:"<%=request.getParameter("applydate")%>",
                bankcode:"<%=request.getParameter("bankcode")%>",
                notifyurl:"<%=request.getParameter("notifyurl")%>",
                callbackurl:"<%=request.getParameter("callbackurl")%>",
                sign:"<%=request.getParameter("sign")%>",
                attach:"<%=request.getParameter("attach")%>",
                productname:"<%=request.getParameter("productname")%>"
            },
            success: function success(res) {
                if (res.errorCode == 2000) {
                    var address=res.json;
                    debugger;
                    window.location.href=address;
                } else {
                    alert(res.data)
                }
            }
        });

    }
    $(function () {

        if (code==400){
            alert(<%=request.getParameter("error")%>);
            window.location.href="http://ds.di1h.cn/Pay_Suibian_callbackurl.html";
        }

    })
</script>
</body>

</html>